<?php
class import_etao_merchant extends PHPUnit_Framework_TestCase{

    public function setUp()
    {
		$this->object = kernel::single('tbdata_api_tbapi');
		$this->cat_model = app::get('tbdata')->model('cats');
		$this->fetch_props_model = app::get('tbdata')->model('fetch_props');
		$this->product_model = app::get('tbdata')->model('product');
		$this->goods_model = app::get('tbdata')->model('goods');
		$this->merchant_model = app::get('tbdata')->model('merchant');
		$this->img_model = app::get('image')->model('image');
    }

    public function testGetcat(){
		$db = kernel::database();

		$fp = fopen('d:\1512_etao.csv', 'r');
		$i = 0;
		while (($data = fgetcsv($fp, 10000, ",")) !== FALSE) {
			if($i==0){
				$cols = $data;
				$i++;
				continue;
			}
			
			foreach($data as $key=>$value){
				$tmp_data[$cols[$key]] = $value;
			}
			$save_data['code'] = $tmp_data['merchant'];
			$save_data['name'] = $tmp_data['merchant'];
			$logo = $tmp_data['merchant_logo'];


			$rows = $this->merchant_model->getList('*',array('code'=>$save_data['name']),0,1);
			if($rows[0]){
				$image_id = $rows[0]['image_id'];
			}else{
				$image_id = $this->img_model->gen_id();
				$save_data['logo'] = $image_id;
				
				$this->img_model->store($logo,$image_id);
				$this->merchant_model->save($save_data);
				unset($save_data['id']);

			}

		}

	}
}
